<template>
  <el-dialog
    width="68%"
    :title="title"
    :visible="innerVisible"
    append-to-body
    @close="$emit('update:innerVisible',false)"
  >
    <div class="search">
      <el-form :inline="true" class="demo-form-inline" size="medium">
        <el-form-item label="商品名称：">
          <el-input placeholder="请输入" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" class="searchBtn">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="main">
      <div class="prev" @click="toPrevPage"><span class="el-icon-arrow-left" /></div>
      <div class="content">
        <ul>
          <li v-for="(item,index) in chooseProList.currentPageRecords" :key="index" @click="replacePro(item)">
            <img v-if="item.skuImage" :src="item.skuImage" alt="">
            <img v-else src="" alt="">
            <!-- 左上角选中小图标 -->
            <img v-if="ischoose" class="chooseImg" src="" alt="">
            <div class="product">{{ item.skuName }}</div>
          </li>
        </ul>
      </div>
      <div class="next" @click="toNextPage"><span class="el-icon-arrow-right" /></div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" class="searchBtn">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'InnerDialog',
  props: {
    innerVisible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '选择商品'
    },
    chooseProList: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      ischoose: false
    }
  },
  methods: {
    toNextPage() {
      if (+this.chooseProList.pageIndex < +this.chooseProList.totalPage) {
        this.$emit('toNextPage')
      }
    },
    toPrevPage() {
      if (this.chooseProList.pageIndex === '1') return
      this.$emit('toPrevPage')
    },
    replacePro(item) {
      // console.log(item)
      this.ischoose = true
      this.$emit('replacePro', item)
    }
  }
}
</script>

<style scoped lang='scss'>
*{
  box-sizing: border-box;
  list-style: none;
  margin: 0;
  padding: 0;
}
.searchBtn{
  width: 80px;
  height: 36px;
}
.main{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
    .prev , .next{
    width: 50px;
    font-size: 50px;
    color: #000;
    cursor: pointer;
    }
    .content{
      flex: 1;
      background-color: #fff;
      ul{
      display: flex;
      flex-wrap: wrap;

      li{
        position: relative;
        width: 150px;
        height: 154px;
        padding: 16px 5px 0;
        color: #606266;
        font-size: 14px;
        background-color: #f6f7fb;
        margin-right: 5px;
        margin-bottom: 5px;
        &:nth-child(5n){
          padding-right: 0;
        }
         text-align: center;
        img{
          width: 84px;
          height: 84px;
          margin: 0 0 5px;
        }
        .chooseImg{
        width: 36px;
        height: 36px;
        position: absolute;
        top: 0;
        left: 0;
        }
      }
      }

    }
}
</style>
